﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Entity
{
    public class ListSanPham
    {
        public List<SanPham_Nhap> sp { get; set; }
        public ListSanPham()
        {
            sp = new List<SanPham_Nhap>();
        }

        public void XoaSP(String masp, String tenncc)
        {
            foreach (SanPham_Nhap a in sp)
            {
                if (a.masp == masp && a.tenncc == tenncc)
                {
                    sp.Remove(a);
                    break;
                }
            }

        }
        public void CapNhatSP(String masp, String tenncc, float soluong, float dongia)
        {
            int idx = -1;
            foreach (SanPham_Nhap a in sp)
            {
                if (a.masp == masp && a.tenncc == tenncc)
                {
                    idx = sp.IndexOf(a);
                    break;
                }
            }
            sp[idx].soluong = soluong;
            sp[idx].dongia = dongia;

        }

        public void ThemSP(SanPham_Nhap sp_nhap)
        {
            bool flag = false;
            int idx = -1;
            foreach (SanPham_Nhap a in sp)
            {
                if (a.tensp == sp_nhap.tensp & a.tenncc == sp_nhap.tenncc)
                {
                    flag = true;
                    idx = sp.IndexOf(a);
                    break;
                }
            }
            if (flag)
            {
                sp[idx].soluong = sp_nhap.soluong ;
                sp[idx].dongia = sp_nhap.dongia;
            }
            else
            {
                sp.Add(sp_nhap);
            }
        }
        
    }
}
